package threading;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-07-05
 * Time: 18:03
 */
public class ThreadDemo26 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);

        Thread t1= new Thread(() -> {
            //相当于num++
            num.getAndIncrement();
            //++num
            //num.incrementAndGet();
            //num--
            //num.getAndDecrement();
            //--num
            //num.decrementAndGet();
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                num.getAndIncrement();
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();
        //得到值
        System.out.println(num.get());
    }
}
